package com.gzlg.hospital.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gzlg.hospital.dao.PatientDao;
import com.gzlg.hospital.pojo.Appointment_details;
import com.gzlg.hospital.pojo.Medical_record;
import com.gzlg.hospital.pojo.Patient;
import com.gzlg.hospital.pojo.Registration;
import com.gzlg.hospital.pojo.query.hQuery;
import com.gzlg.hospital.service.PatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;

@Service

public class PatientServiceImpl implements PatientService {
    @Autowired
    private PatientDao patientDao;
    @Override
    public PageInfo<Patient> listPatientByName(hQuery hQuery) {
        PageHelper.startPage(hQuery.getPageNum(), hQuery.getPageSize());
        return new PageInfo<Patient>(patientDao.listPatientByName(hQuery));
    }

    @Override
    public PageInfo<Medical_record> listMedicalRecordByName(hQuery hQuery) {
        PageHelper.startPage(hQuery.getPageNum(), hQuery.getPageSize());
        return new PageInfo<Medical_record>(patientDao.listMedicalRecordByName(hQuery));
    }

    @Override
    public Patient getPatientByName(String name) {
        return patientDao.getPatientByName(name);
    }

    @Override
    public Patient  getPatientById(Integer id) {
        return patientDao.getPatientById(id);
    }


    //患者登陆
    @Override
    public Patient getPatientByAccount(String account) {
        return patientDao.getPatientByAccount(account);
    }
    //患者页面自己的病历信息
    @Override
    public PageInfo<Medical_record> getMedicalRecordByPatientID(Integer patient_id, hQuery hQuery) {
        PageHelper.startPage(hQuery.getPageNum(), hQuery.getPageSize());
        return new PageInfo<Medical_record>(patientDao.getMedicalRecordByPatientID(patient_id));
    }
    //患者页面查看某一条病历信息
    @Override
    public PageInfo<Medical_record> getMedicalRecordByIdPatientID(Map<String, Integer> map,hQuery hQuery) {
        PageHelper.startPage(hQuery.getPageNum(), hQuery.getPageSize());
        return new PageInfo<Medical_record>(patientDao.getMedicalRecordByIdPatientID(map));
    }
    //挂号
    @Override
    public Boolean insertRegistration(Integer patient_id,String symptoms) {
        Registration registration = new Registration();
        registration.setPatient_id(patient_id);
        registration.setRegister_time(new Date());
        registration.setSymptoms(symptoms);
        registration.setStatus("待就诊");
        return patientDao.insertRegistration(registration) > 0;
    }
    //患者获得自己全部挂号信息
    @Override
    public PageInfo<Registration> listRegistrationById(Integer patient_id, hQuery hQuery) {
        PageHelper.startPage(hQuery.getPageNum(), hQuery.getPageSize());
        return new PageInfo<Registration>(patientDao.listRegistrationById(patient_id));
    }
    //患者获得某条挂号信息
    @Override
    public PageInfo<Registration> getRegistrationByIdPatientId(Map<String, Integer> map, hQuery hQuery) {
        PageHelper.startPage(hQuery.getPageNum(), hQuery.getPageSize());
        return new PageInfo<Registration>(patientDao.getRegistrationByIdPatientId(map));
    }
    //患者查看要处理的信息
    @Override
    public PageInfo<Appointment_details> listAppointmentDetailsByPatientId(Integer patient_id, hQuery hQuery) {
        PageHelper.startPage(hQuery.getPageNum(), hQuery.getPageSize());
        return new PageInfo<Appointment_details>(patientDao.listAppointmentDetailsByPatientId(patient_id));
    }
    //患者查看一条处理的信息
    @Override
    public PageInfo<Appointment_details> listAppointmentDetailsByRegistrationIdPatientId(Map<String, Integer> map, hQuery hQuery) {
        PageHelper.startPage(hQuery.getPageNum(), hQuery.getPageSize());
        return new PageInfo<Appointment_details>(patientDao.listAppointmentDetailsByRegistrationIdPatientId(map));
    }
    //添加患者
    @Override
    public Boolean insertPatient(Patient patient) {
        return patientDao.insertPatient(patient) ;
    }
}
